<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;

class buildMaterialBalanceJson extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'buildMaterialBalanceJson';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    public function handle()
    {
        // if(date('Y-m-d')==date('Y-m-25')){
        $material = DB::table('akbus_material')->get()->toArray();
        $n = 0;
        foreach ($material as $k => $v) {
            DB::table('akbus_material_balance')
                ->insertGetId(
                    [
                        'material_id' => $v['id'],
                        'amount'      => $v['amount'],
                        'date'        => date('Y-m-01'),
                    ]
                );
            $n++;
        }
        file_put_contents('22.txt', $n."***".date('Y-m-d H:i:s'));
    }
    // }
}
